package forminrecipe.data;

import javax.swing.DefaultListModel;
import javax.swing.event.TableModelListener;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableModel;

public class BrowserTableModel extends AbstractTableModel {
	private DefaultListModel nameList;
	private DefaultListModel catagoryList;
	private DefaultListModel difficultyList;
	private DefaultListModel timeList;
	private DefaultListModel  idList;
	private int columbCount = 4;
	private DefaultListModel allData;
	
	//constuctor
	public BrowserTableModel(){
		nameList= new DefaultListModel();
		catagoryList= new DefaultListModel();
		difficultyList= new DefaultListModel();
		timeList= new DefaultListModel();
		idList = new DefaultListModel();
		allData = new DefaultListModel();
	}
	
	public String getColumnName(int col) {
        return constants.browserTableHeadings[col];
    }

	public RecipeData getRecipeData(int index){
		return (RecipeData) allData.get(index);
	}
	public void addRow(RecipeData recipeData){
		allData.addElement(recipeData);
		nameList.addElement(recipeData.name);
		catagoryList.addElement(recipeData.catagory);
		timeList.addElement(recipeData.time);
		difficultyList.addElement(recipeData.difficulty);
		idList.addElement(recipeData.id);
	}

	public int getID(int possition){
		return Integer.parseInt(idList.get(possition).toString());
	}
	
	@Override
	public int getColumnCount() {
		return columbCount;
	}

	@Override
	public int getRowCount() {
		// TODO Auto-generated method stub
		return nameList.getSize();
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		// TODO Auto-generated method stub
		if(columnIndex == 0){
			return nameList.getElementAt(rowIndex);
		}else if(columnIndex == 1){
			return catagoryList.getElementAt(rowIndex);
		}else if(columnIndex == 2){
			return difficultyList.getElementAt(rowIndex);
		}else if(columnIndex == 3){
			return timeList.getElementAt(rowIndex);
		}
		else{
			return null;
		}
	}
}
